#!/bin/bash

# ----------------------------------------------------------------------------------------------------------------------
# add new sh file for first time, you should pull commond for the file in terminal. 
# eg: 
# chmod a+x autobuild.sh
# chmod a+x sendmail-ex
# 路径配置方法：
# 一、“/media/versions”：
# 在linux的终端下，将“//10.20.30.5/spreadtrum_smartphone” 挂载到"/media/versions"，并分配当前用户的uid以得到相应的读写权限。
# 二、"BASE_DIR"：
# 这个取代码到本机的目录"BASE_DIR"路径可自己根据习惯来定；~ 表示是用户目录，注意不能加双引号，那样路径会不一样的。
# 如：
# 	local BASE_DIR=~/work
# 或
# 	local BASE_DIR=/media/work
# 注意：
# 　　如果要修改这二个参数值中的任何一个，都要把本文件和涉及到的配置文件中，所有的参数都更改为一致的。
# ----------------------------------------------------------------------------------------------------------------------

function help()
{
	# ./autobuild.sh [项目版本号] [鼎智项目名] [客户项目名] [编译模式] [延时时间] [分支类型] [强制取拷条件] [前一个版本的svn号]
	cat help.txt
}

# 自动发邮件: $1客户版本号 $2鼎智项目名 $3客户项目名 $4鼎智项目版本目录 $5邮件内容类别(build_err|build_succ)
function do_send_mail()
{
	if ! [ -f ${autobuild_path}/sendmail-ex ]; then
		echo "Warring: Missing ${autobuild_path}/sendmail-ex"
		return
	fi

	local smver=$1
	local smtpj=$2
	local smcpj=$3
	local smdir=$4
	local smtype=$5
	local smtxt=smail.txt
	# 构造邮件内容
	echo "from:`logname`@topwisesz.com" > ./${smtxt}
	echo "to:Android-0xLJD6C7C4DCCAD6BBFAB2BFz@topwisesz.com" >> ./${smtxt}
	echo "cc:" >> ./${smtxt}
	if [ "build_err" = "${smtype}" ]; then
		echo "subject:${smcpj} 项目编译出错，请开发人员尽快修改。谢谢支持！" >> ./${smtxt}
		echo "content: " >> ./${smtxt}
		echo "${smtpj}项目编译出错，详细看如下路径${smcpj}项目相关的log文件：" >> ./${smtxt}
		echo "\\\\data1\spreadtrum_smartphone\software release\内部版本发布\error" >> ./${smtxt}
	else
		echo "subject:${smcpj}_${smver} 内部测试版本发布，请安排测试。谢谢支持！" >> ./${smtxt}
		echo "content: " >> ./${smtxt}
		echo "\\\\data1\spreadtrum_smartphone\software release\内部版本发布\\${smdir}\\${smtpj}\\${smcpj}\\${smcpj}_${smver}" >> ./${smtxt}
		echo "" >> ./${smtxt}
		cat ./log.txt >> ./${smtxt}
	fi

	if [ "build_err" = "${smtype}" -o "build_succ" = "${smtype}" ]; then
		# 调用 sendmail 发送邮件
		cp ${autobuild_path}/sendmail-ex ./sendmail-ex
		./sendmail-ex ./${smtxt}
		rm -f ./sendmail-ex ./log.txt ./${smtxt}
	fi
}

# 产生 修改记录 log.txt: $1客户版本号 $2客户项目前一个svn号
function do_version_log()
{
	local lver=$1
	local lsvn=$2
	if [[ "${lsvn:0:2}" =~ r([0-9]) ]]; then
		lsvn=`echo ${lsvn} | cut -b 2-`
		local svnr=`svn info | grep 版本:| head -n 1 | sed -e "s/版本: /r/g" | cut -b 2-`
		if [ "${svnr}" = "" ] ; then
			svnr=`LANG=en_US.UTF-8;svn info | grep Revision:|sed -e "s/Revision: /r/g" | cut -b 2-`
		fi
		./autoGetLog.sh ${lsvn} ${svnr} ${lver}
		return 0
	else
		echo "do_version_log: ${lsvn} do not auto get svn log"
		return 1
	fi
}

# 拷到发版本目录下，并修改版本发布记录: $1客户版本号 $2鼎智项目名 $3客户项目名 $4客户项目前一个svn号　$5鼎智项目版本目录
function do_release_version()
{
	local cver=$1
	local ctpj=$2
	local ccpj=$3
	local csvn=$4
	local cdir=$5
	local emlst=null
	local epac=$(find ./idh.code/customize/out/${ccpj}_${cver} -name "*.pac" -o -name "*.p5c")
	if [ "" = "${epac}" ];then
		local dvdir="/media/versions/software release/内部版本发布/error"
		if ! [ -d "${dvdir}" ]; then
			mkdir -p "${dvdir}"
		fi
		# 如果没有挂载，就不会有这个目录，也不会自动创建成功这个目录
		if [ -d "${dvdir}" ]; then
			cp ./idh.code/customize/dontmodify/log/${ctpj}.${ccpj}*.log "${dvdir}"
			if [ "" != "`ls ./idh.code/customize/dontmodify/log/${ctpj}.${ccpj}*.log`" ]; then
				# 发布“编译错误信息”邮件
				emlst=build_err
			fi
		fi
		echo "do_release_version: no pac and p5c file"
	else
		ctpj=`echo $2 | sed "s/./\u&/g"`
		local dvdir=/media/versions
		if [ -d "${dvdir}" ]; then
			dvdir="/media/versions/software release/内部版本发布/${cdir}/${ctpj}/${ccpj}"
			emlst=build_succ
		else
			dvdir=~/内部版本发布/${cdir}/${ctpj}/${ccpj}
		fi
		if ! [ -d "${dvdir}" ]; then
			mkdir -p "${dvdir}"
		fi
		# 如果没有挂载，就不会有这个目录，也不会自动创建成功这个目录
		if [ -d "${dvdir}" ]; then
			# 拷版本
			cp -rf ./idh.code/customize/out/${ccpj}_${cver} "${dvdir}"
			# 导出svn记录
			do_version_log ${cver} ${csvn}
			local dover=$?
			if [ ${dover} -eq 0 ]; then
				# 改记录
				local rnote=${ccpj}_release_note.txt
				local retxt=`find "${dvdir}" -maxdepth 1 -name "${rnote}" -print | head -n 1`
				if [ "" = "${retxt}" ];then
					echo "${ccpj}" > ./${rnote}
				else
					cp -f "${dvdir}/${rnote}" ./${rnote}
				fi
				sed "/${ccpj}/r ./log.txt" -i ./${rnote}
				mv ./${rnote} "${dvdir}/${rnote}"
			fi
		fi
	fi
	# 发布邮件
	do_send_mail ${cver} ${ctpj} ${ccpj} ${cdir} ${emlst}
}

# 产生 svn_log.txt
function do_svn_log()
{
	local backup_cur_path=`pwd`
	local hsvnlogpath=${1}/`basename ${2}`
	cd ${hsvnlogpath}
	local svnlogfile=./svn_log.txt
	local svnr=`svn info | grep 版本:| head -n 1 | sed -e "s/版本: /r/g"`
	if [ "${svnr}" = "" ] ; then
		svnr=`LANG=en_US.UTF-8;svn info | grep Revision:|sed -e "s/Revision: /r/g"`
	fi
	echo "${hsvnlogpath}" > ${svnlogfile}
	echo "全取全编的日期:" >> ${svnlogfile}
	echo "    `date`" >> ${svnlogfile}
	echo "全取全编的svn号：" >> ${svnlogfile}
	echo "    ${svnr}" >> ${svnlogfile}
	echo "------------------------------------------------------" >> ${svnlogfile}
	echo "版本编译人员或开发人员在当前目录临时手动修改的内容点：" >> ${svnlogfile}
	echo "    " >> ${svnlogfile}
	echo "------------------------------------------------------" >> ${svnlogfile}
	echo "版本编译人员手动修改、删除、更新的svn号：" >> ${svnlogfile}
	echo "    " >> ${svnlogfile}
	echo "------------------------------------------------------" >> ${svnlogfile}
	cd "${backup_cur_path}"
}

function svn_co_dir()
{
	local svn_version=$1
	local svn_dir=$2
	local target_dir=$3
	local ignore_dir=$4
	for i in `ls $target_dir`; do 
		if [ -d "$target_dir/$i" ]; then
			if [ "$i" = "${ignore_dir}" ]; then 
				svn co -r $svn_version $svn_dir/$i $target_dir/$i --depth immediates
			else
				echo "need to svn co $target_dir/$i"
				svn co -r $svn_version $svn_dir/$i $target_dir/$i --depth infinity
			fi
		fi
	done
}

# 支持4个参数：项目名 目标目录 svn目录 [版本号]
function svn_co_prj()
{
	local prj=$1
	local target_dir=$2
	local svn_root=$3
	local svn_version=$4
	if [ "$svn_version" = "" ]; then
		svn_version=`svn info $svn_root| grep "^版本:" | awk -F":" '{print $2}'`
	fi
	echo "svn_co_prj: $svn_version"  | tee -a ./../autobuild.log

	test -d $target_dir && echo "$target_dir 已经存在，必须先删除它。确认删除？y/n" && read -n 1 -t 60
	if [ "$REPLY" = "n" -o "$REPLY" = "N" ]; then
		exit
	else
		rm -rf $target_dir
	fi

	svn co -r $svn_version $svn_root $target_dir --depth immediates
	svn_co_dir $svn_version $svn_root $target_dir "idh.code"
	svn_co_dir $svn_version $svn_root/idh.code $target_dir/idh.code "customize"
	svn_co_dir $svn_version $svn_root/idh.code/customize $target_dir/idh.code/customize "res"

	for i in `svn ls $svn_root/idh.code/customize/res | egrep -v "^pa|^pe|^pc|^pk|^p8|^f8|^ph|^pq"`; do 
		echo "need to svn co $svn_root/ih.code/customize/res/$i"
		svn co -r $svn_version $svn_root/idh.code/customize/res/$i $target_dir/idh.code/customize/res/$i --depth infinity
	done
	for i in `svn ls $svn_root/idh.code/customize/res | egrep "^pa|^pe|^pc|^pk|^p8|^f8|^ph|^pq"`; do 
		if [ -d "$target_dir/idh.code/customize/res/$i" ]; then
			rm -rf $target_dir/idh.code/customize/res/$i
		fi
		if [ "$i" = "$prj/" ]; then 
			svn co -r $svn_version $svn_root/idh.code/customize/res/$i $target_dir/idh.code/customize/res/$i --depth infinity
		else
			echo "need to svn ignore $svn_root/idh.code/customize/res/$i"
		fi
	done
}

function do_svn_co()
{
	local svn_co_dir=$1
	local svn_co_path=$2
	local svn_co_prj=$3
	local svn_co_base=$4
	# 重新创建log文件
	echo "${svn_co_dir} autobuild log start" > ./autobuild.log
	# 重新保存新目录为基础代码目录
	echo "${svn_co_dir}" > ./.baseDirName
	mkdir -p ./${svn_co_dir}
	echo "svn co start: `date`"  | tee -a ./autobuild.log
	cd ./${svn_co_dir}
	echo "正在从svn上取代码，大约需要半个小时左右。请稍候..."
	if [ "newcodenocp" = "${svn_co_base}" ]; then
		local tmdir=`basename ${svn_co_path}`
		svn_co_prj ${svn_co_prj} `pwd`/${tmdir} ${svn_co_path}
	else
		svn co ${svn_co_path}
	fi
	cd ..
	# 产生 svn_log.txt
	do_svn_log ${svn_co_dir} ${svn_co_path}
	echo "svn co end: `date`"  | tee -a ./autobuild.log
}

function do_main()
{
	if [ "${1}" = "-h" -o "${1}" = "-help" -o "${6}" = "" ]; then
		help
		exit
	fi
	autobuild_path=`pwd`

	local CUSTOMIZE_VERSION=${1}
	local TOPWISE_PROJECT=${2}
	local TOPWISE_CUSTOMER=${3}
	local PROJ_OPT=${4}
	local SLEEP_TIME=${5}
	local SVN_TYPE=${6}
	local NEW_CODE=${7}
	local CUSPROJ_VER=$8
	# 这个BASE_DIR基础路径可自己根据习惯来定；~ 表示是用户目录，注意不能加双引号，那样路径会不一样的
	local BASE_DIR=~/work
	local PROJ_DIR="${TOPWISE_CUSTOMER}_${PROJ_OPT}"
	local SVN_PATH=""
	local TOPPROJ_DIR=""
	local foreingflag=""
	local time_flag=""

	# 外文版本编译选项特殊处理
	local PROJ_OPTS=(${PROJ_OPT//:/ })
	local PROJ_OPTS_NUM=${#PROJ_OPTS[@]} 
	if [ $PROJ_OPTS_NUM -eq 1 ]; then
		if [ ! "$PROJ_OPT" = "user" -a ! "$PROJ_OPT" = "usr" -a ! "$PROJ_OPT" = "userdebug" -a ! "$PROJ_OPT" = "eng" ]; then
			help
			exit
		fi
	elif [ $PROJ_OPTS_NUM -eq 2 ]; then
		if [ ! "${PROJ_OPTS[0]}" = "user" -a ! "${PROJ_OPTS[0]}" = "usr" -a ! "${PROJ_OPTS[0]}" = "userdebug" -a ! "${PROJ_OPTS[0]}" = "eng" ]; then
			help
			exit
		fi
		if [ ! "${PROJ_OPTS[1]}" = "multi" ]; then
			help
			exit
		fi
		# 外文版本的编译选项中有“:multi”，但编译路径目录中不得有“:”，所以将“:”转换为“_”
		local tmp_opt=(${PROJ_OPT//:/_})
		PROJ_DIR="${TOPWISE_CUSTOMER}_${tmp_opt}"
		# 外文版本放在外文版本目录下
		foreingflag=外文版
	else
		help
		exit
	fi

	if [ ! "$SLEEP_TIME" = "now" ]; then
		if [[ ! "$SLEEP_TIME" =~ [0-9]+[s|m|h] ]]; then
			echo -e "\e[1;33m时间格式是：now或者5s或者5m或者5h\e[0m"
			exit
		fi
	fi

	# 获得对应的svn路径
	case ${TOPWISE_PROJECT} in
		pa[0-9][0-9][0-9]|fa[0-9][0-9][0-9])
			echo "${TOPWISE_PROJECT} is 6825 project"
			;;
		pe[0-9][0-9][0-9])
			echo "${TOPWISE_PROJECT} is 8825 project"
			;;
		pc[0-9][0-9][0-9])
			echo "${TOPWISE_PROJECT} is 6825c project"
			;;
		pk[0-9][0-9][0-9])
			echo "${TOPWISE_PROJECT} is 8825c project"
			;;
		p8[0-9][0-9][0-9]|f8[0-9][0-9][0-9])
			echo "${TOPWISE_PROJECT} is 8830 project"
			;;
		ph[0-9][0-9][0-9])
			echo "${TOPWISE_PROJECT} is 7715 project"
			;;
		pq[0-9][0-9][0-9])
			echo "${TOPWISE_PROJECT} is 6815 project"
			;;
		*)
			echo -e "\e[1;33m鼎智4.0.3项目名必须是这类格式的：paXXX,peXXX,pcXXX,pkXXX,p8XXX,f8XXX,phXXX,pqXXX\e[0m"
			exit
			;;
	esac
	case ${SVN_TYPE} in
		6825_branch)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8810/branches/MocorDroid_4.0.3_sc6825"
			TOPPROJ_DIR=4.0.3
			;;
		6825_trunk)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8810/trunk/MocorDroid_4.0.3_sc6825"
			TOPPROJ_DIR=4.0.3
			;;
		6825_trunk_P05)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8810/trunk/MocorDroid_4.0.3_sc6825_P05"
			TOPPROJ_DIR=4.0.3
			;;
		8825_cmcc)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/branches/MocorDroid_4.0.3_sc8825_cmcc" 
			TOPPROJ_DIR=4.0.3_cmcc
			;;
		8825_branch)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/branches/MocorDroid_4.0.3" 
			TOPPROJ_DIR=4.0.3_misc
			;;
		8825_trunk)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/trunk/MocorDroid_4.0.3" 
			TOPPROJ_DIR=4.0.3_misc
			;;
		6825c_branch)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/branches/MocorDroid_4.0.3_sc6825c"
			TOPPROJ_DIR=4.0.3_25c
			;;
		6825c_trunk)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/trunk/MocorDroid_4.0.3_sc6825c"
			TOPPROJ_DIR=4.0.3_25c
			;;
		8830_branch)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/branches/MocorDroid_4.1.3_sc8830"
			TOPPROJ_DIR=4.1.3_8830
			;;
		8830_trunk)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/trunk/MocorDroid_4.1.3_sc8830"
			TOPPROJ_DIR=4.1.3_8830
			;;
		6815_branch)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc7715/branches/MocorDroid_4.4.3_sc6815"
			TOPPROJ_DIR=4.4.2_7715
			;;
		6815_trunk)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc7715/trunk/MocorDroid_4.4.3_sc6815"
			TOPPROJ_DIR=4.4.2_7715
			;;
		7715_branch)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc7715/branches/MocorDroid_4.4.3_sc7715"
			TOPPROJ_DIR=4.4.2_7715
			;;
		7715_trunk)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc7715/trunk/MocorDroid_4.4.3_sc7715"
			TOPPROJ_DIR=4.4.2_7715
			;;
		6825c_alios_branch)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/branches/MocorDroid_4.0.3_W13.48_yunos"
			TOPPROJ_DIR=4.0.3_ali
			;;
		6825c_alios_trunk)
			SVN_PATH="svn+ssh://svn@10.20.30.20/spreadtrum/sc8825/trunk/MocorDroid_4.0.3_W13.48_yunos"
			TOPPROJ_DIR=4.0.3_ali
			;;
		*)
			echo -e "\e[1;33m找不到对应的svn，请确认“分支类型”是否输入正确？\e[0m"
			exit
			;;
	esac
	if [ "" != "${foreingflag}" ]; then
		TOPPROJ_DIR=${TOPPROJ_DIR}/${foreingflag}
	fi

	# 后面二个参数为空，则默认不用代码拷贝方式，即与最开始的自动编译脚本做法一样，且不会获取svn记录
	if [ "" = "${NEW_CODE}" ]; then
		CUSPROJ_VER=null
		NEW_CODE=newcodenocp
	# 后面一个参数为空
	elif [ "" = "${CUSPROJ_VER}" ]; then
		# 最后一个参数是svn号，则默认不用代码拷贝方式，且自动取svn记录
		if [[ "${NEW_CODE:0:2}" =~ r([0-9]) ]]; then
			CUSPROJ_VER=${NEW_CODE}
			NEW_CODE=newcodenocp
		# 最后一个参数不是svn号，则不会自动取svn记录
		else
			CUSPROJ_VER=null
		fi
	# 如果最后二个参数传错，即倒数第二个参数为svn号，则自动对调参数内容
	elif [[ "${NEW_CODE:0:2}" =~ r([0-9]) ]]; then
		local tmp=${CUSPROJ_VER}
		CUSPROJ_VER=${NEW_CODE}
		NEW_CODE=${tmp}
	fi

	# 输出信息以便版本编译人员核对
	echo "svn path: ${SVN_PATH}"
	echo "proj name: ${PROJ_DIR}"
	echo "build inputs: ${CUSTOMIZE_VERSION} ${TOPWISE_PROJECT} ${TOPWISE_CUSTOMER} ${PROJ_OPT}"
	echo "sleep time: ${SLEEP_TIME}"
	echo "select option: ${NEW_CODE}"
	echo "pre svn id: ${CUSPROJ_VER}"
	echo "注意：核对如上参数信息"

	# 延时操作
	if [ "${SLEEP_TIME}" = "now" ]; then
		sleep 1s
	else
		sleep ${SLEEP_TIME}
	fi

	# 基础代码目录创建
	BASE_DIR=${BASE_DIR}/${SVN_TYPE}
	test -d ${BASE_DIR} || mkdir -p ${BASE_DIR}
	cd ${BASE_DIR}
	local CUR_DATE=`date +%Y`
	CUR_DATE=${CUR_DATE}`date +%m`
	CUR_DATE=${CUR_DATE}`date +%d`
	local CUR_TIME=`date +%H`
	CUR_TIME=${CUR_TIME}`date +%M`
	case ${NEW_CODE} in
		newcode)
			do_svn_co ${CUR_DATE}_${CUR_TIME} ${SVN_PATH}
			;;
		newcodenocp)
			do_svn_co ${CUR_DATE}_${CUR_TIME}_${PROJ_DIR} ${SVN_PATH} ${TOPWISE_PROJECT} ${NEW_CODE}
			;;
		*)
			# 判断是否要重新取基础代码
			if [ -f ./.baseDirName ]; then
				local BASE_DATE=`cat ./.baseDirName | cut -b -8`
				if [ "${CUR_DATE}" != "${BASE_DATE}" ]; then
					do_svn_co ${CUR_DATE}_${CUR_TIME} ${SVN_PATH}
				else
					echo "${CUR_DATE}_${CUR_TIME} autobuild log start" >> ./autobuild.log
				fi
			else
				do_svn_co ${CUR_DATE}_${CUR_TIME} ${SVN_PATH}
			fi
			;;
	esac
	echo "public path: ${BASE_DIR}" >> ./autobuild.log

	# 是否要拷贝代码目录
	if [ "newcodenocp" != "${NEW_CODE}" ]; then
		# 获得当前基础目录的相对路径
		BASE_DIR=`cat ./.baseDirName`
		BASE_DIR=${BASE_DIR}/`basename ${SVN_PATH}`
		# 创建客户项目代码目录
		if [ -d ./${PROJ_DIR} ]; then
			echo "正在删除客户项目目录下旧代码，请稍候..." | tee -a ./autobuild.log
			echo "del old code start: `date`" >> ./autobuild.log
			rm -rf ./${PROJ_DIR}/*
			echo "del old code end: `date`" >> ./autobuild.log
			echo "完成删除客户项目目录下旧代码" | tee -a ./autobuild.log
		fi
		mkdir -p ./${PROJ_DIR}/idh.code
		cd ./${PROJ_DIR}
		# 拷贝代码
		echo "开始拷贝基础代码到客户目录，请稍候..." | tee -a ../autobuild.log
		echo "code cp start: `date`" >> ../autobuild.log
		cp -f ../.baseDirName ./baseDirName.txt
		cp -f ../${BASE_DIR}/autoGetLog.sh ./
		# 拷贝 svn_log.txt
		cp -f ../${BASE_DIR}/svn_log.txt ./
		# 提供给autoGetLog.sh获取svn号用
		cp -rf ../${BASE_DIR}/.svn ./
		# 提供给pac_main.sh获取svn号用
		cp -rf ../${BASE_DIR}/idh.code/.svn ./idh.code/
		cp -rf ../${BASE_DIR}/idh.images ./
		for name in `(ls ../${BASE_DIR}/idh.code)`; do
			if [ -d ../${BASE_DIR}/idh.code/${name} ]; then
				if [ "customize" = "${name}" ]; then
					cp -rf ../${BASE_DIR}/idh.code/${name} ./idh.code/
				else
					mkdir -p ./idh.code/${name}
					rsync -r --links --delete  --exclude=".svn" ../${BASE_DIR}/idh.code/${name}/ ./idh.code/${name}
				fi
			else
				cp -f ../${BASE_DIR}/idh.code/${name} ./idh.code/
			fi
		done
		echo "code cp end: `date`" >> ../autobuild.log
		echo "完成拷贝基础代码到客户目录" | tee -a ../autobuild.log
	else
		cd ${CUR_DATE}_${CUR_TIME}_${PROJ_DIR}/`basename ${SVN_PATH}`
	fi

	# 进入idh.code开始编译版本
	cd ./idh.code
	test -f ../../../autobuild.log && echo "${TOPWISE_CUSTOMER} build start: `date`" >> ../../../autobuild.log
	test -f ../../autobuild.log && echo "${TOPWISE_CUSTOMER} build start: `date`" >> ../../autobuild.log
	. ./build/envsetup.sh &&
	mk -o=${PROJ_OPT} ${TOPWISE_PROJECT} ${TOPWISE_CUSTOMER} m update-api &&
	mk -o=${PROJ_OPT} ${TOPWISE_PROJECT} ${TOPWISE_CUSTOMER} pac ${CUSTOMIZE_VERSION}
	test -f ../../../autobuild.log && echo "${TOPWISE_CUSTOMER} build end: `date`" >> ../../../autobuild.log
	test -f ../../autobuild.log && echo "${TOPWISE_CUSTOMER} build end: `date`" >> ../../autobuild.log

	# 回到上一级目录下
	cd ..
	# 拷到发版本目录下，并修改版本发布记录: $1客户版本号 $2鼎智项目名 $3客户项目名 $4客户项目前一个svn号　$5鼎智项目版本目录
	do_release_version ${CUSTOMIZE_VERSION} ${TOPWISE_PROJECT} ${TOPWISE_CUSTOMER} ${CUSPROJ_VER} "${TOPPROJ_DIR}"
}

do_main ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8}

